package com.study.bean的作用域.service;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试 bean的作用域
 *
 * @author chenhs
 * @date 2019/9/7
 */
public class Test {
	private String xmlPath = "com/study/bean的作用域/applicationContext.xml";
	private ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
	
	@org.junit.Test
	public void Demo() {
		CarServiceImpl singleton1 = applicationContext.getBean("carSingleton", CarServiceImpl.class);
		CarServiceImpl singleton2 = applicationContext.getBean("carSingleton", CarServiceImpl.class);
		if (singleton1 == singleton2) {
			System.out.println(singleton1 + ":" + singleton2 + "地址相等为同一对象");
		} else {
			System.out.println(singleton1 + ":" + singleton2 + "地址不等为不同对象");
		}
		
		
	}
	@org.junit.Test
	public void Demo2() {
		CarServiceImpl carPrototype1 = applicationContext.getBean("carPrototype", CarServiceImpl.class);
		CarServiceImpl carPrototype2 = applicationContext.getBean("carPrototype", CarServiceImpl.class);
		if (carPrototype1 == carPrototype2) {
			System.out.println(carPrototype1 + ":" + carPrototype2 + "地址相等为同一对象");
		} else {
			System.out.println(carPrototype1 + ":" + carPrototype2 + "地址不等为不同对象");
		}
	}
}
